
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>编辑混入 &#8212; Django 3.2.6.dev 文档</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../../genindex.html" />
    <link rel="search" title="搜索" href="../../search.html" />
    <link rel="next" title="基于日期的混入" href="mixins-date-based.html" />
    <link rel="prev" title="多对象混入" href="mixins-multiple-object.html" />



 
<script src="../../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 3.2.6.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="mixins-multiple-object.html" title="多对象混入">previous</a>
     |
    <a href="../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="mixins-date-based.html" title="基于日期的混入">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-class-based-views-mixins-editing">
            
  <div class="section" id="s-editing-mixins">
<span id="editing-mixins"></span><h1>编辑混入<a class="headerlink" href="#editing-mixins" title="永久链接至标题">¶</a></h1>
<p>以下混入用于构建 Django 的编辑视图。</p>
<ul class="simple">
<li><a class="reference internal" href="#django.views.generic.edit.FormMixin" title="django.views.generic.edit.FormMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.edit.FormMixin</span></code></a></li>
<li><a class="reference internal" href="#django.views.generic.edit.ModelFormMixin" title="django.views.generic.edit.ModelFormMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.edit.ModelFormMixin</span></code></a></li>
<li><a class="reference internal" href="#django.views.generic.edit.ProcessFormView" title="django.views.generic.edit.ProcessFormView"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.edit.ProcessFormView</span></code></a></li>
<li><a class="reference internal" href="#django.views.generic.edit.DeletionMixin" title="django.views.generic.edit.DeletionMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.edit.DeletionMixin</span></code></a></li>
</ul>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">如何将这些视图组合成编辑视图的例子可以在 <a class="reference internal" href="generic-editing.html"><span class="doc">通用编辑视图</span></a> 的文档中找到。</p>
</div>
<div class="section" id="s-formmixin">
<span id="formmixin"></span><h2><code class="docutils literal notranslate"><span class="pre">FormMixin</span></code><a class="headerlink" href="#formmixin" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.edit.FormMixin">
<em class="property">class </em><code class="descclassname">django.views.generic.edit.</code><code class="descname">FormMixin</code><a class="headerlink" href="#django.views.generic.edit.FormMixin" title="永久链接至目标">¶</a></dt>
<dd><p>一个提供创建和显示表单的设施的混入类。</p>
<p><strong>混入</strong></p>
<ul class="simple">
<li><a class="reference internal" href="mixins-simple.html#django.views.generic.base.ContextMixin" title="django.views.generic.base.ContextMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.base.ContextMixin</span></code></a></li>
</ul>
<p><a href="#id1"><span class="problematic" id="id2">**</span></a>方法和属性*</p>
<dl class="attribute">
<dt id="django.views.generic.edit.FormMixin.initial">
<code class="descname">initial</code><a class="headerlink" href="#django.views.generic.edit.FormMixin.initial" title="永久链接至目标">¶</a></dt>
<dd><p>包含表单初始数据的字典。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.edit.FormMixin.form_class">
<code class="descname">form_class</code><a class="headerlink" href="#django.views.generic.edit.FormMixin.form_class" title="永久链接至目标">¶</a></dt>
<dd><p>要实例化的表单类。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.edit.FormMixin.success_url">
<code class="descname">success_url</code><a class="headerlink" href="#django.views.generic.edit.FormMixin.success_url" title="永久链接至目标">¶</a></dt>
<dd><p>表单处理成功后重定向到的 URL。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.edit.FormMixin.prefix">
<code class="descname">prefix</code><a class="headerlink" href="#django.views.generic.edit.FormMixin.prefix" title="永久链接至目标">¶</a></dt>
<dd><p>生成的表单的 <a class="reference internal" href="../forms/api.html#django.forms.Form.prefix" title="django.forms.Form.prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">prefix</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.FormMixin.get_initial">
<code class="descname">get_initial</code>()<a class="headerlink" href="#django.views.generic.edit.FormMixin.get_initial" title="永久链接至目标">¶</a></dt>
<dd><p>检索表单的初始数据。默认情况下，返回 <a class="reference internal" href="#django.views.generic.edit.FormMixin.initial" title="django.views.generic.edit.FormMixin.initial"><code class="xref py py-attr docutils literal notranslate"><span class="pre">initial</span></code></a> 的副本。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.FormMixin.get_form_class">
<code class="descname">get_form_class</code>()<a class="headerlink" href="#django.views.generic.edit.FormMixin.get_form_class" title="永久链接至目标">¶</a></dt>
<dd><p>检索要实例化的表单类。默认情况下 <a class="reference internal" href="#django.views.generic.edit.FormMixin.form_class" title="django.views.generic.edit.FormMixin.form_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">form_class</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.FormMixin.get_form">
<code class="descname">get_form</code>(<em>form_class=None</em>)<a class="headerlink" href="#django.views.generic.edit.FormMixin.get_form" title="永久链接至目标">¶</a></dt>
<dd><p>使用 <a class="reference internal" href="#django.views.generic.edit.FormMixin.get_form_kwargs" title="django.views.generic.edit.FormMixin.get_form_kwargs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_form_kwargs()</span></code></a> 实例化 <code class="docutils literal notranslate"><span class="pre">form_class</span></code>。如果没有提供 <code class="docutils literal notranslate"><span class="pre">form_class</span></code>，将使用 <a class="reference internal" href="#django.views.generic.edit.FormMixin.get_form_class" title="django.views.generic.edit.FormMixin.get_form_class"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_form_class()</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.FormMixin.get_form_kwargs">
<code class="descname">get_form_kwargs</code>()<a class="headerlink" href="#django.views.generic.edit.FormMixin.get_form_kwargs" title="永久链接至目标">¶</a></dt>
<dd><p>构建实例化表单所需的关键字参数。</p>
<p><code class="docutils literal notranslate"><span class="pre">initial`</span> <span class="pre">`参数设置为</span> <span class="pre">:meth:`.get_initial`。如果请求是</span> <span class="pre">``POST</span></code> 或 <code class="docutils literal notranslate"><span class="pre">PUT</span></code>，还将提供请求数据（<code class="docutils literal notranslate"><span class="pre">request.POST</span></code> 和 <code class="docutils literal notranslate"><span class="pre">request.FILES</span></code>）。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.FormMixin.get_prefix">
<code class="descname">get_prefix</code>()<a class="headerlink" href="#django.views.generic.edit.FormMixin.get_prefix" title="永久链接至目标">¶</a></dt>
<dd><p>为生成的表单确定 <a class="reference internal" href="../forms/api.html#django.forms.Form.prefix" title="django.forms.Form.prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">prefix</span></code></a>。默认返回 <a class="reference internal" href="#django.views.generic.edit.FormMixin.prefix" title="django.views.generic.edit.FormMixin.prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">prefix</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.FormMixin.get_success_url">
<code class="descname">get_success_url</code>()<a class="headerlink" href="#django.views.generic.edit.FormMixin.get_success_url" title="永久链接至目标">¶</a></dt>
<dd><p>当表单成功验证后，确定重定向到的 URL。默认返回 <a class="reference internal" href="#django.views.generic.edit.FormMixin.success_url" title="django.views.generic.edit.FormMixin.success_url"><code class="xref py py-attr docutils literal notranslate"><span class="pre">success_url</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.FormMixin.form_valid">
<code class="descname">form_valid</code>(<em>form</em>)<a class="headerlink" href="#django.views.generic.edit.FormMixin.form_valid" title="永久链接至目标">¶</a></dt>
<dd><p>重定向到 <a class="reference internal" href="#django.views.generic.edit.FormMixin.get_success_url" title="django.views.generic.edit.FormMixin.get_success_url"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_success_url()</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.FormMixin.form_invalid">
<code class="descname">form_invalid</code>(<em>form</em>)<a class="headerlink" href="#django.views.generic.edit.FormMixin.form_invalid" title="永久链接至目标">¶</a></dt>
<dd><p>渲染一个响应，提供无效的表单作为上下文。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.FormMixin.get_context_data">
<code class="descname">get_context_data</code>(<em>**kwargs</em>)<a class="headerlink" href="#django.views.generic.edit.FormMixin.get_context_data" title="永久链接至目标">¶</a></dt>
<dd><p>调用 <a class="reference internal" href="#django.views.generic.edit.FormMixin.get_form" title="django.views.generic.edit.FormMixin.get_form"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_form()</span></code></a> 并将结果添加到名为 'form' 的上下文数据中。</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-modelformmixin">
<span id="modelformmixin"></span><h2><code class="docutils literal notranslate"><span class="pre">ModelFormMixin</span></code><a class="headerlink" href="#modelformmixin" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.edit.ModelFormMixin">
<em class="property">class </em><code class="descclassname">django.views.generic.edit.</code><code class="descname">ModelFormMixin</code><a class="headerlink" href="#django.views.generic.edit.ModelFormMixin" title="永久链接至目标">¶</a></dt>
<dd><p>一个在 <code class="docutils literal notranslate"><span class="pre">ModelForms</span></code> 上工作的表单混入，而不是一个独立的表单。</p>
<p>由于这是 <a class="reference internal" href="mixins-single-object.html#django.views.generic.detail.SingleObjectMixin" title="django.views.generic.detail.SingleObjectMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">SingleObjectMixin</span></code></a> 的一个子类，所以这个混入的实例可以访问 <a class="reference internal" href="mixins-single-object.html#django.views.generic.detail.SingleObjectMixin.model" title="django.views.generic.detail.SingleObjectMixin.model"><code class="xref py py-attr docutils literal notranslate"><span class="pre">model</span></code></a> 和 <a class="reference internal" href="mixins-single-object.html#django.views.generic.detail.SingleObjectMixin.queryset" title="django.views.generic.detail.SingleObjectMixin.queryset"><code class="xref py py-attr docutils literal notranslate"><span class="pre">queryset</span></code></a> 属性，描述 <code class="docutils literal notranslate"><span class="pre">ModelForm</span></code> 所操纵的对象类型。</p>
<p>如果你同时指定了 <a class="reference internal" href="#django.views.generic.edit.ModelFormMixin.fields" title="django.views.generic.edit.ModelFormMixin.fields"><code class="xref py py-attr docutils literal notranslate"><span class="pre">fields</span></code></a> 和 <a class="reference internal" href="#django.views.generic.edit.FormMixin.form_class" title="django.views.generic.edit.FormMixin.form_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">form_class</span></code></a> 属性，将引发 <a class="reference internal" href="../exceptions.html#django.core.exceptions.ImproperlyConfigured" title="django.core.exceptions.ImproperlyConfigured"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImproperlyConfigured</span></code></a> 异常。</p>
<p><strong>混入</strong></p>
<ul class="simple">
<li><a class="reference internal" href="#django.views.generic.edit.FormMixin" title="django.views.generic.edit.FormMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.edit.FormMixin</span></code></a></li>
<li><a class="reference internal" href="mixins-single-object.html#django.views.generic.detail.SingleObjectMixin" title="django.views.generic.detail.SingleObjectMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.detail.SingleObjectMixin</span></code></a></li>
</ul>
<p><a href="#id1"><span class="problematic" id="id2">**</span></a>方法和属性*</p>
<dl class="attribute">
<dt id="django.views.generic.edit.ModelFormMixin.model">
<code class="descname">model</code><a class="headerlink" href="#django.views.generic.edit.ModelFormMixin.model" title="永久链接至目标">¶</a></dt>
<dd><p>一个模型类。可以明确提供，否则将通过检查 <code class="docutils literal notranslate"><span class="pre">self.object</span></code> 或 <a class="reference internal" href="mixins-single-object.html#django.views.generic.detail.SingleObjectMixin.queryset" title="django.views.generic.detail.SingleObjectMixin.queryset"><code class="xref py py-attr docutils literal notranslate"><span class="pre">queryset</span></code></a> 来确定。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.edit.ModelFormMixin.fields">
<code class="descname">fields</code><a class="headerlink" href="#django.views.generic.edit.ModelFormMixin.fields" title="永久链接至目标">¶</a></dt>
<dd><p>字段名的列表。这与 <a class="reference internal" href="../../topics/forms/modelforms.html#django.forms.ModelForm" title="django.forms.ModelForm"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelForm</span></code></a> 的 <code class="docutils literal notranslate"><span class="pre">Meta.fields</span></code> 属性的解释方式相同。</p>
<p>如果你是自动生成表单类，这个属性是必须的（比如使用 <code class="docutils literal notranslate"><span class="pre">model</span></code>）。忽略这个属性将导致 <a class="reference internal" href="../exceptions.html#django.core.exceptions.ImproperlyConfigured" title="django.core.exceptions.ImproperlyConfigured"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImproperlyConfigured</span></code></a> 异常。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.edit.ModelFormMixin.success_url">
<code class="descname">success_url</code><a class="headerlink" href="#django.views.generic.edit.ModelFormMixin.success_url" title="永久链接至目标">¶</a></dt>
<dd><p>表单处理成功后重定向到的 URL。</p>
<p><code class="docutils literal notranslate"><span class="pre">success_url</span></code> 可以包含字典字符串格式，它将被插入到对象的字段属性中。例如，你可以使用 <code class="docutils literal notranslate"><span class="pre">success_url=&quot;/polls/{slug}/&quot;</span></code> 来重定向到一个由模型上的 <code class="docutils literal notranslate"><span class="pre">slug</span></code> 字段组成的 URL。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.ModelFormMixin.get_form_class">
<code class="descname">get_form_class</code>()<a class="headerlink" href="#django.views.generic.edit.ModelFormMixin.get_form_class" title="永久链接至目标">¶</a></dt>
<dd><p>检索要实例化的表单类。如果提供了 <a class="reference internal" href="#django.views.generic.edit.FormMixin.form_class" title="django.views.generic.edit.FormMixin.form_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">form_class</span></code></a>，将使用该类。否则，将使用与 <a class="reference internal" href="mixins-single-object.html#django.views.generic.detail.SingleObjectMixin.queryset" title="django.views.generic.detail.SingleObjectMixin.queryset"><code class="xref py py-attr docutils literal notranslate"><span class="pre">queryset</span></code></a> 相关联的模型，或与 <a class="reference internal" href="mixins-single-object.html#django.views.generic.detail.SingleObjectMixin.model" title="django.views.generic.detail.SingleObjectMixin.model"><code class="xref py py-attr docutils literal notranslate"><span class="pre">model</span></code></a> 实例化，这取决于提供的属性。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.ModelFormMixin.get_form_kwargs">
<code class="descname">get_form_kwargs</code>()<a class="headerlink" href="#django.views.generic.edit.ModelFormMixin.get_form_kwargs" title="永久链接至目标">¶</a></dt>
<dd><p>将当前实例（<code class="docutils literal notranslate"><span class="pre">self.object</span></code>）添加到标准 <a class="reference internal" href="#django.views.generic.edit.FormMixin.get_form_kwargs" title="django.views.generic.edit.FormMixin.get_form_kwargs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_form_kwargs()</span></code></a> 中。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.ModelFormMixin.get_success_url">
<code class="descname">get_success_url</code>()<a class="headerlink" href="#django.views.generic.edit.ModelFormMixin.get_success_url" title="永久链接至目标">¶</a></dt>
<dd><p>当表单成功验证后，确定重定向到的 URL。如果提供了 <a class="reference internal" href="#django.views.generic.edit.ModelFormMixin.success_url" title="django.views.generic.edit.ModelFormMixin.success_url"><code class="xref py py-attr docutils literal notranslate"><span class="pre">django.views.generic.edit.ModelFormMixin.success_url</span></code></a>，则返回 <a class="reference internal" href="#django.views.generic.edit.ModelFormMixin.success_url" title="django.views.generic.edit.ModelFormMixin.success_url"><code class="xref py py-attr docutils literal notranslate"><span class="pre">django.views.generic.edit.ModelFormMixin.success_url</span></code></a>；否则，尝试使用对象的 <code class="docutils literal notranslate"><span class="pre">get_absolute_url()</span></code>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.ModelFormMixin.form_valid">
<code class="descname">form_valid</code>(<em>form</em>)<a class="headerlink" href="#django.views.generic.edit.ModelFormMixin.form_valid" title="永久链接至目标">¶</a></dt>
<dd><p>保存表单实例，为视图设置当前对象，并重定向到 <a class="reference internal" href="#django.views.generic.edit.FormMixin.get_success_url" title="django.views.generic.edit.FormMixin.get_success_url"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_success_url()</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.ModelFormMixin.form_invalid">
<code class="descname">form_invalid</code>(<em>form</em>)<a class="headerlink" href="#django.views.generic.edit.ModelFormMixin.form_invalid" title="永久链接至目标">¶</a></dt>
<dd><p>渲染一个响应，提供无效的表单作为上下文。</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-processformview">
<span id="processformview"></span><h2><code class="docutils literal notranslate"><span class="pre">ProcessFormView</span></code><a class="headerlink" href="#processformview" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.edit.ProcessFormView">
<em class="property">class </em><code class="descclassname">django.views.generic.edit.</code><code class="descname">ProcessFormView</code><a class="headerlink" href="#django.views.generic.edit.ProcessFormView" title="永久链接至目标">¶</a></dt>
<dd><p>一个提供基本 HTTP GET 和 POST 工作流程的混入。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">这个命名为 'ProcessFormView'，直接继承自 <code class="xref py py-class docutils literal notranslate"><span class="pre">django.view.generic.base.View</span></code>，但如果独立使用就会中断，所以它更像是一个混入。</p>
</div>
<p><strong>扩展</strong></p>
<ul class="simple">
<li><a class="reference internal" href="base.html#django.views.generic.base.View" title="django.views.generic.base.View"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.base.View</span></code></a></li>
</ul>
<p><a href="#id1"><span class="problematic" id="id2">**</span></a>方法和属性*</p>
<dl class="method">
<dt id="django.views.generic.edit.ProcessFormView.get">
<code class="descname">get</code>(<em>request</em>, <em>*args</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.views.generic.edit.ProcessFormView.get" title="永久链接至目标">¶</a></dt>
<dd><p>使用 <a class="reference internal" href="#django.views.generic.edit.FormMixin.get_context_data" title="django.views.generic.edit.FormMixin.get_context_data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_context_data()</span></code></a> 创建的上下文来渲染响应。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.ProcessFormView.post">
<code class="descname">post</code>(<em>request</em>, <em>*args</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.views.generic.edit.ProcessFormView.post" title="永久链接至目标">¶</a></dt>
<dd><p>构造一个表单，检查表单的有效性，并进行相应的处理。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.ProcessFormView.put">
<code class="descname">put</code>(<em>*args</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.views.generic.edit.ProcessFormView.put" title="永久链接至目标">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">PUT</span></code> 动作也会被处理，并将所有参数传递给 <a class="reference internal" href="#django.views.generic.edit.ProcessFormView.post" title="django.views.generic.edit.ProcessFormView.post"><code class="xref py py-meth docutils literal notranslate"><span class="pre">post()</span></code></a>。</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-deletionmixin">
<span id="deletionmixin"></span><h2><code class="docutils literal notranslate"><span class="pre">DeletionMixin</span></code><a class="headerlink" href="#deletionmixin" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.edit.DeletionMixin">
<em class="property">class </em><code class="descclassname">django.views.generic.edit.</code><code class="descname">DeletionMixin</code><a class="headerlink" href="#django.views.generic.edit.DeletionMixin" title="永久链接至目标">¶</a></dt>
<dd><p>启用处理 <code class="docutils literal notranslate"><span class="pre">DELETE</span></code> http 动作。</p>
<p><a href="#id1"><span class="problematic" id="id2">**</span></a>方法和属性*</p>
<dl class="attribute">
<dt id="django.views.generic.edit.DeletionMixin.success_url">
<code class="descname">success_url</code><a class="headerlink" href="#django.views.generic.edit.DeletionMixin.success_url" title="永久链接至目标">¶</a></dt>
<dd><p>当指定对象被成功删除时，重定向到的网址。</p>
<p><code class="docutils literal notranslate"><span class="pre">success_url</span></code> 可以包含字典字符串格式，它将被插入到对象的字段属性中。例如，你可以使用 <code class="docutils literal notranslate"><span class="pre">success_url=&quot;/parent/{parent_id}/&quot;</span></code> 重定向到一个模型上由 <code class="docutils literal notranslate"><span class="pre">parent_id</span></code> 字段组成的 URL。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.DeletionMixin.delete">
<code class="descname">delete</code>(<em>request</em>, <em>*args</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.views.generic.edit.DeletionMixin.delete" title="永久链接至目标">¶</a></dt>
<dd><p>检索目标对象并调用其 <code class="docutils literal notranslate"><span class="pre">delete()</span></code> 方法，然后重定向到成功的 URL。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.edit.DeletionMixin.get_success_url">
<code class="descname">get_success_url</code>()<a class="headerlink" href="#django.views.generic.edit.DeletionMixin.get_success_url" title="永久链接至目标">¶</a></dt>
<dd><p>当指定对象被成功删除时，返回重定向到的 url。默认返回 <a class="reference internal" href="#django.views.generic.edit.DeletionMixin.success_url" title="django.views.generic.edit.DeletionMixin.success_url"><code class="xref py py-attr docutils literal notranslate"><span class="pre">success_url</span></code></a>。</p>
</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">编辑混入</a><ul>
<li><a class="reference internal" href="#formmixin"><code class="docutils literal notranslate"><span class="pre">FormMixin</span></code></a></li>
<li><a class="reference internal" href="#modelformmixin"><code class="docutils literal notranslate"><span class="pre">ModelFormMixin</span></code></a></li>
<li><a class="reference internal" href="#processformview"><code class="docutils literal notranslate"><span class="pre">ProcessFormView</span></code></a></li>
<li><a class="reference internal" href="#deletionmixin"><code class="docutils literal notranslate"><span class="pre">DeletionMixin</span></code></a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="mixins-multiple-object.html"
                        title="上一章">多对象混入</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="mixins-date-based.html"
                        title="下一章">基于日期的混入</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/ref/class-based-views/mixins-editing.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">7月 23, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="mixins-multiple-object.html" title="多对象混入">previous</a>
     |
    <a href="../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="mixins-date-based.html" title="基于日期的混入">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>